package com.dfbz.springboot_project.service.impl;

import com.dfbz.springboot_project.entity.Role;
import com.dfbz.springboot_project.mapper.AdminRoleMapper;
import com.dfbz.springboot_project.service.AdminRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Map;

@Service
@Transactional
public class AdminRoleServiceImpl implements AdminRoleService {
    @Autowired
    AdminRoleMapper adminRoleMapper;
    @Override
    public void updateSelective(Map<String, Object> params) {
        if (params.containsKey("Aid")){
            adminRoleMapper.DeleteByAid((Integer) params.get("Aid"));
        }
        if (params.containsKey("roles")&&params.get("roles")!=""){
            adminRoleMapper.InsertSelective((Integer) params.get("Aid"), (ArrayList<Role>) params.get("roles"));
        }
    }
    @Override
    public void deleteByAid(Integer Aid){
        adminRoleMapper.DeleteByAid(Aid);
    }
}
